package com.tutor.lzm.function.teacher.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tutor.lzm.R;
import com.tutor.lzm.bean.TeacherExperienceBean;
import com.tutor.lzm.function.teacher.act.AddTeacherExperienceAct;
import com.tutor.lzm.utils.AppViewHolder;
import com.tutor.syslib.view.RichTextView;

import java.util.List;


/**
 * Created by zzgpc on 2017-9-23.
 * 教育经历适配器
 */
public class TeacherExperienceAdapter extends BaseAdapter {

    private Context context;
    private List<TeacherExperienceBean> objects;
    private boolean isEdit = false;

    public TeacherExperienceAdapter(Context context, List<TeacherExperienceBean> list, boolean isEdit) {
        this.context = context;
        this.objects = list;
        this.isEdit = isEdit;
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public Object getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_teacher_experience, null);
        }

        final TeacherExperienceBean item = objects.get(position);
        TextView tvEducationDate = AppViewHolder.get(convertView, R.id.tv_education_date);
        TextView tvtEducationSpace = AppViewHolder.get(convertView, R.id.tv_education_space);
        TextView tvtEducationContent = AppViewHolder.get(convertView, R.id.tv_education_content);
        RichTextView tvEdit = AppViewHolder.get(convertView, R.id.rich_edit);
        if (isEdit) {
            tvEdit.setVisibility(View.VISIBLE);
        } else {
            tvEdit.setVisibility(View.GONE);
        }
        tvEducationDate.setText(item.startDate + "—" + item.endDate);
        tvtEducationSpace.setText(item.title);
        tvtEducationContent.setText(item.description);
        tvEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AddTeacherExperienceAct.start(context,item);
            }
        });

        return convertView;
    }
}
